﻿using System;
using System.Collections.Generic;
using System.Text;

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using GetooLibs;

namespace GTOFileMaker
{
    class Program
    {
        static void Main(string[] args)
        {
            string DatabasePath="d:/getoo/webroot/";
            GetooDatabaseFile currentDB = new GetooDatabaseFile();

            int finishedFlag = 0;
            
            int dbVerison = Properties.Settings.Default.DBVersion;
            
            dbVerison++;
            Properties.Settings.Default.DBVersion=dbVerison;
            Properties.Settings.Default.Save();
            

            //GetooDatabaseFile db = new GetooDatabaseFile();


            Console.WriteLine(dbVerison);

            //build update pack
            string[] dirs = Directory.GetDirectories(DatabasePath,"*",SearchOption.AllDirectories);
            foreach (string  dir in dirs)
            {
                string[] files = Directory.GetFiles(dir);
                foreach (string  file in files)
                {
                    currentDB.Files.Add(new GetooFile(
                        file.Replace(dir, string.Empty), 
                        Utility.GetFileHash(file), 
                        0,
                        File.GetLastWriteTime(file),
                        dir.Replace(DatabasePath,string.Empty)));

                    File.Move(file, dir+"\\"+Utility.GetFileHash(file));
                }
                finishedFlag++;
            }

            currentDB.FileName = "Getoo.DB";
            currentDB.Version = dbVerison;
            currentDB.ModifyDate = DateTime.Now;


            Utility.SaveGetooDatabaseFile(DatabasePath + "getoo.db",currentDB);
        }
    }
}
